/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: ${USER}
 * Date: ${YEAR}-${MONTH}-${DAY}
 * Time: ${TIME}
 */
class Animal{
    public String name;
    public int age;
    public void walk(String name){
        System.out.println(name + "在跑");
    }


class Dog extends Animal{
    public void walk(Animal name){
        System.out.println(name + "在用狗腿跑");
    }
    public void swimming(){
        System.out.println("用狗腿游泳");
    }


}
class Bird extends  Animal {

    public void flying(){
        System.out.println("在用翅膀飞");//子类特有方法
    }
    public void walk(Animal name) {
        System.out.println(name + "在用鸟腿跑");
    }
}

public class Main {
    public void main(String[] args) {
        //向上转型
//        Animal animal = new Dog();
        //发生多态
//        animal.walk();
//        animal.walk();
        Dog dog = new Dog();
//        //调用子类特有的方法
        Animal animal = new Animal();
//
//        //((Dog)animal).flying();//向下转型但不安全，Dog类型中仍无法找到flying
        if (animal instanceof Dog) {//若当前引用类型为Dog可用Dog强转类型
            ((Dog) animal).swimming();
        }
        if (animal instanceof Bird) {//若当前引用类型为Bird可用Bird强转类型
            ((Bird) animal).flying();
        }

    }
}
